#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e5+2;

const int b1 = 31;
const int b2 = 29;
const int mod = 1e9+7;

string s[3];
bool visit[3];
int arr[3];
size_t ans = 1e6;

int nex[N];

inline void getNex(string s){
    int j=-1,i=0;
    nex[0] = -1;
    while(s[i]!='\0'){
        if(j<0||s[i]==s[j]){
            ++i;
            ++j;
            nex[i] = j;
        }else{
            j = nex[j];
        }
    }
}

inline bool kmp(string s1, string s2){
    int i=0,j=0;
    while(s1[i]!='\0'){
        if(j<0||s1[i]==s2[j]){
            ++i;
            ++j;
            if(s2[j]=='\0') return true;
        }else{
            j = nex[j];
        }
    }
    return false;
}

inline LL qpow(int b,int n){
    LL res = 1;
    LL base = b;
    while(n){
        if(n&1){
            res = res*base%mod;
        }
        base = base*base%mod;
        n >>= 1;
    }
    return res;
}

inline string match(string s1,string s2){
    LL num11=0,num12=0;
    LL num21=0,num22=0;
    int i1 = s1.length()-1;
    int i2 = 0;
    int ch = 0;
    while(i1>=0&&s2[i2]!='\0'){
        num11 = (num11+(s1[i1]-'a'+1)*qpow(b1,s1.length()-i1-1)%mod)%mod;
        num12 = (num12+(s1[i1]-'a'+1)*qpow(b2,s1.length()-i1-1)%mod)%mod;

        num21 = (num21*b1%mod+(s2[i2]-'a'+1) )%mod;
        num22 = (num22*b2%mod+(s2[i2]-'a'+1) )%mod;
        if(num11==num21&&num12==num22){
            ch = i2+1;
        }
        i1--;
        i2++;
    }

    num11 = num12 = 0;
    if(s1.length()>=s2.length()){
        // int len = s2.length();
        // int i;
        // for(i=0;s2[i]!='\0';i++){
        //     num11 = (num11*b1%mod+(s1[i]-'a'+1) )%mod;
        //     num12 = (num12*b2%mod+(s1[i]-'a'+1) )%mod;
        // }
        // while(s1[i]!='\0'){
        //     if(num11==num21&&num12==num22) return s1;
        //     num11 = ( (num11*b1+(s1[i]-'a'+1) )%mod-qpow(b1,len)*(s1[i-len]-'a'+1)%mod +mod)%mod;
        //     num12 = ( (num12*b2+(s1[i]-'a'+1) )%mod-qpow(b2,len)*(s1[i-len]-'a'+1)%mod +mod)%mod;
        //     ++i;
        // }
        
        getNex(s2);
        if(kmp(s1,s2)) return s1;
    }
    string sa = s1.substr(0,s1.length()-ch)+s2;
    return sa;
}

inline void solve(){
    string s12 = match(s[0],s[1]);
    string s3 = match(s12,s[2]);
    ans = min(ans, s3.length());
    // cout<<s12<<" "<<s3<<endl;
    // exit(-1);
}

void dfs(int idx){
    if(idx==3){
        solve();
        return;
    }
    for(int i=0;i<3;i++){
        if(!visit[i]){
            visit[i] = true;
            arr[idx] = i;
            dfs(idx+1);
        }
    }
}

int main(){
    cin>>s[0]>>s[1]>>s[2];
    memset(visit,0,sizeof(visit));
    dfs(0);
    cout<<ans<<"\n";
    return 0;
}